load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")

proto_library(
    name = "helloworld_proto",
    srcs = ["src/main/proto/helloworld.proto"],
)

java_proto_library(
    name = "helloworld_java_proto",
    deps = [":helloworld_proto"],
)

java_grpc_library(
    name = "helloworld_java_grpc",
    srcs = [":helloworld_proto"],
    deps = [":helloworld_java_proto"],
)

proto_library(
    name = "hello_streaming_proto",
    srcs = [
        "src/main/proto/hello_streaming.proto",
    ],
)

java_proto_library(
    name = "hello_streaming_java_proto",
    deps = [":hello_streaming_proto"],
)

java_grpc_library(
    name = "hello_streaming_java_grpc",
    srcs = [":hello_streaming_proto"],
    deps = [":hello_streaming_java_proto"],
)

proto_library(
    name = "route_guide_proto",
    srcs = ["src/main/proto/route_guide.proto"],
)

java_proto_library(
    name = "route_guide_java_proto",
    deps = [":route_guide_proto"],
)

java_grpc_library(
    name = "route_guide_java_grpc",
    srcs = [":route_guide_proto"],
    deps = [":route_guide_java_proto"],
)

java_library(
    name = "examples",
    testonly = 1,
    srcs = glob(
        ["src/main/java/**/*.java"],
    ),
    resources = glob(
        ["src/main/resources/**"],
    ),
    runtime_deps = [
        "@io_grpc_grpc_java//netty",
    ],
    deps = [
        ":hello_streaming_java_grpc",
        ":hello_streaming_java_proto",
        ":helloworld_java_grpc",
        ":helloworld_java_proto",
        ":route_guide_java_grpc",
        ":route_guide_java_proto",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//api",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@maven//:com_google_api_grpc_proto_google_common_protos",
        "@maven//:com_google_code_findbugs_jsr305",
        "@maven//:com_google_code_gson_gson",
        "@maven//:com_google_guava_guava",
    ],
)

java_binary(
    name = "hello-world-client",
    testonly = 1,
    main_class = "io.grpc.examples.helloworld.HelloWorldClient",
    runtime_deps = [
        ":examples",
    ],
)

java_binary(
    name = "hello-world-server",
    testonly = 1,
    main_class = "io.grpc.examples.helloworld.HelloWorldServer",
    runtime_deps = [
        ":examples",
    ],
)

java_binary(
    name = "route-guide-client",
    testonly = 1,
    main_class = "io.grpc.examples.routeguide.RouteGuideClient",
    runtime_deps = [
        ":examples",
    ],
)

java_binary(
    name = "route-guide-server",
    testonly = 1,
    main_class = "io.grpc.examples.routeguide.RouteGuideServer",
    runtime_deps = [
        ":examples",
    ],
)

java_binary(
    name = "manual-flow-control-client",
    testonly = 1,
    main_class = "io.grpc.examples.manualflowcontrol.ManualFlowControlClient",
    runtime_deps = [
        ":examples",
    ],
)

java_binary(
    name = "manual-flow-control-server",
    testonly = 1,
    main_class = "io.grpc.examples.manualflowcontrol.ManualFlowControlServer",
    runtime_deps = [
        ":examples",
    ],
)
